package cn.javaxxw.springboot;

import cn.javaxxw.springboot.interceptor.LogInterceptor;
import cn.javaxxw.springboot.properties.LogProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 功能描述: 自动配置
 * @author  TuYong
 * @date  2022/9/7 20:55
 */
@Configuration
@EnableConfigurationProperties({LogProperties.class})
@ConditionalOnProperty(
        prefix = "request.log",
        name = {"enabled"},
        havingValue = "true"
)
public class LogAutoConfiguration implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LogInterceptor()).addPathPatterns("/api/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
